#!/usr/bin/env python3
"""
Simple Frontend Status Test
"""

import requests
import sys
from datetime import datetime

def test_frontend():
    """Test frontend application"""
    frontend_url = "http://localhost:8101"

    print(f"Testing frontend: {frontend_url}")
    print(f"Time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")

    try:
        response = requests.get(frontend_url, timeout=10)

        if response.status_code == 200:
            print(f"SUCCESS: Frontend responding (status: {response.status_code})")
            print(f"Response time: {response.elapsed.total_seconds() * 1000:.0f}ms")

            content = response.text
            if "Vue" in content:
                print("Vue.js loaded")
            if "Element Plus" in content or "element-plus" in content:
                print("Element Plus loaded")
            if "UC" in content or "ulcerative" in content.lower():
                print("UC system content found")

            print("Frontend test PASSED!")
            print(f"Open in browser: {frontend_url}")
            return True
        else:
            print(f"ERROR: Frontend responded with status {response.status_code}")
            return False

    except requests.exceptions.ConnectionError:
        print("ERROR: Cannot connect to frontend")
        print("Make sure frontend is running (npm run dev)")
        return False
    except Exception as e:
        print(f"ERROR: Test failed - {e}")
        return False

def main():
    print("=" * 50)
    print("UC System Frontend Status Check")
    print("=" * 50)

    frontend_ok = test_frontend()

    print("=" * 50)
    if frontend_ok:
        print("RESULT: Frontend application is working!")
        sys.exit(0)
    else:
        print("RESULT: Frontend application has issues!")
        sys.exit(1)

if __name__ == "__main__":
    main()